﻿using MediatR;
using MS.BasicData.Domain;
using MS.BasicData.Infrastructure;
using MS.BasicData.Infrastructure.IBaseRepository;

namespace MS.BasicData.Read.API.Applications.Permissionss
{
    public class CreatePermiRequestHandler : IRequestHandler<CreatePermiRequestModel, ApiRestult>
    {
        private readonly IPermisBaseBaseRepository _permissionsRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="permissionsRepository"></param>
        public CreatePermiRequestHandler(IPermisBaseBaseRepository permissionsRepository)
        {
            _permissionsRepository = permissionsRepository;
        }

        public async Task<ApiRestult> Handle(CreatePermiRequestModel request, CancellationToken cancellationToken)
        {
            ApiRestult restult = new ApiRestult
            {
                isSuc = true,
                Message = "创建权限成功",
                Code = Restult.Success
            };
            Permissions permiss = new Permissions
            {
                PermissionsName = request.PermissionsName
            };
            await _permissionsRepository.InsertAsync(permiss);
            return restult;
        }
    }


    public class CreatePermiRequestModel  : IRequest<ApiRestult>
    {
        /// <summary>
        /// 权限名称
        /// </summary>
        public string PermissionsName { get; set; } = string.Empty;

    }

}
